<?php
// require_once(dirname(dirname(dirname(__FILE__))) . '/core.php');
    if(get_mobile_member_info()){
        $member_info = get_mobile_member_info();
	    if (chksubmit()){
            $obj_validate = new Validate();
            $pdc_amount = abs(floatval($_POST['pdc_amount']));
            $validate_arr[] = array("input"=>$pdc_amount, "require"=>"true",'validator'=>'Compare','operator'=>'>=',"to"=>'0.01',"message"=>"提现金额不能小于0.01元");
            $validate_arr[] = array("input"=>$_POST["pdc_bank_name"], "require"=>"true","message"=>"请填写收款银行");
            $validate_arr[] = array("input"=>$_POST["pdc_bank_no"], "require"=>"true","message"=>"请填写收款账号");
            $validate_arr[] = array("input"=>$_POST["pdc_bank_user"], "require"=>"true","message"=>"请填写收款人姓名");
            $obj_validate -> validateparam = $validate_arr;
            $error = $obj_validate->validate();
            if ($error != ''){
	            echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
                echo "<script>alert('".$error."');history.back()</script>";
                exit;
            }
            // print_r($_POST);exit;
            $model_pd = Model('predeposit');
            $model_member = Model('member');
            $member_info = $model_member->getMemberInfoByID($member_info['member_id']);
            //验证支付密码
            //if (md5($_POST['password']) != $member_info['member_paypwd']) {
            //    showDialog('支付密码错误','','error');
            //}
            //验证金额是否足够
            if (floatval($member_info['available_predeposit']) < $pdc_amount){
	            echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
                echo "<script>alert('您的金额不足，请重新填写');history.back();</script>";
                exit;
            }
            try {
                $model_pd->beginTransaction();
                $pdc_sn = $model_pd->makeSn();
                $data = array();

                $data['pdc_sn'] = $pdc_sn;
                $data['pdc_member_id'] = $member_info['member_id'];
                $data['pdc_member_name'] = $member_info['member_name'];
                $data['pdc_amount'] = $pdc_amount;
                $data['pdc_bank_name'] = $_POST['pdc_bank_name'];
                $data['pdc_bank_no'] = $_POST['pdc_bank_no'];
                $data['pdc_bank_user'] = $_POST['pdc_bank_user'];
                $data['pdc_add_time'] = TIMESTAMP;
                $data['pdc_payment_state'] = 0;
                // $data['pdc_store_id'] = $_SESSION['store_id'];
                $insert = $model_pd->addPdCash($data);
                if (!$insert) {
	                echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
                    echo "<script>alert('添加失败');history.back();</script>";
                    exit;
                }
                //冻结可用预存款
                $data = array();
                $data['member_id'] = $member_info['member_id'];
                $data['member_name'] = $member_info['member_name'];
                $data['amount'] = $pdc_amount;
                $data['order_sn'] = $pdc_sn;
                $model_pd->changePd('cash_apply',$data);
                $model_pd->commit();
                echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
                echo "<script>alert('添加成功');window.location.href='pdcashlist.php';</script>";
            } catch (Exception $e) {
                $model_pd->rollback();
                echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
                echo "<script>alert('添加失败');history.back();</script>";
            }
        }
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>申请提现</title>
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/main.css">
	<link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/member.css">
    <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/new.css">
    <link rel="stylesheet" type="text/css" href="/wap/css/font-awesome.min.css">
    <style>
        .tab-line .tab-line-item a i.home, .tab-line .tab-line-item a i.cart, .tab-line .tab-line-item a i.member, .tab-line .tab-line-item a i.category{
            width:20px;
            height:20px;
        }
        #bottom .nav a{
            font-size: 16px;
        }
        .header-wrap{
            height: 50px;
            margin-top: 0;
            background:#f8f8f8;
        }
        #header_faker{
            height: 10px !important;
        }
        .add_address{
            background:#eee;
            color:#333;
            border:0;
            width: 90%;
            margin:10px auto;
            border-radius:5px;
        }
        #bottom .nav .tab-line-item i{
            font-size: 18px !important;
        }
        #bottom .nav a{
            font-size: 14px;
        }
    </style>
</head>
<body>
    <header id="header">
    </header>
    <div class="address-opera">
        <style>
    .address-ocnt p, .address-ocnt div.new-select-wp{
        padding-left: 0;
    }
</style>
<form action="" method="post" enctype="multipart/form-data">
    <input type="hidden" name="form_submit" value="ok" />
<div class="address-ocnt">
            <div class="address-octlt">申请提现</div>
            <p>提现金额：</p>
            <p>
               <input type="text" name="pdc_amount" id="pdc_amount" class="input-30"> 
            </p>
            <p>(可用余额：<font color="red"><?php echo $member_info['available_predeposit'];?></font>元)</p>
            <p>收款银行：<span></span></p>
            <p>
            <input name="pdc_bank_name" type="text" class="input-30" id="pdc_bank_name" maxlength="40">
            </p>
            <p class="hint">
                <?php 
                   $model_article = Model('article');
                   $article = $model_article->getOneArticle(45);
                   echo $article['article_content'];
                ?>
            </p>
            <p>收款帐号：<span></span></p>
            <p>
            <input name="pdc_bank_no" type="text" class="input-30" id="pdc_bank_no" maxlength="30">
            </p>
            <p class="hint">银行账号或虚拟账号(支付宝、财付通等账号)</p>
            <p>开户人姓名：<span></span></p>
            <p>
            <input name="pdc_bank_user" type="text" class="input-30" id="pdc_bank_user" maxlength="10">
            </p>
            <p class="hint">收款账号的开户人姓名</p>
        </div>
        <div class="error-tips"></div>
        <input type="submit" class="add_address mt10" value="保存修改">
        <!-- <a class="add_address mt10" href="javascript:;">保存修改</a> -->
        </form>
    </div>
    <div id="footer"></div>
    <script type="text/javascript" src="/wap/e_tpl/js/zepto.min.js"></script>
    <script type="text/javascript" src="/wap/e_tpl/js/config.js"></script>
    <script type="text/javascript" src="/wap/e_tpl/js/template.js"></script>
    <script type="text/javascript" src="/wap/e_tpl/js/common.js"></script>
    <script type="text/javascript" src="/wap/e_tpl/js/simple-plugin.js"></script>
    <script type="text/javascript" src="/wap/js/tmpl/common-top.js"></script>
    <script type="text/javascript" src="/wap/e_tpl/js/tmpl/footer.js"></script>
</body>
</html>
<?php }?>
